package com.heima.article.controller.v1;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.apis.article.ArticleCollectionControllerApi;
import com.heima.model.article.pojos.ApCollection;
import com.heima.article.service.ApCollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/api/v1/articleCollection")
public class ArticleCollectionController implements ArticleCollectionControllerApi {

    @Autowired
    ApCollectionService apCollectionService;

    /**
     * 根据文章id和实体id查询
     *
     * @param entryId
     * @param articleId
     * @return
     */
    @GetMapping("/collection/{entryId}/{articleId}")
    @Override
    public ApCollection getCollection(@PathVariable("entryId") Integer entryId, @PathVariable("articleId") Long articleId) {

        return apCollectionService.getOne(Wrappers.<ApCollection>lambdaQuery().eq(ApCollection::getArticleId,articleId).eq(ApCollection::getEntryId,entryId));
    }
}
